import requests
import re

# 资产管理首页url
url = r'http://172.16.22.104:8080/bsams/front/login.do'
url1 = r'http://172.16.22.104:8080/bsams/front/vericode.do'
url2 = r'http://172.16.22.104:8080/bsams/front/asset/asset_list.do'
url_news_add = r'http://172.16.22.104:8080/bsams/front/asset/asset_new.do'
url_update = r'http://172.16.22.104:8080/bsams/front/asset/asset_update.do'
url_borrow = r'http://172.16.22.104:8080/bsams/front/asset/asset_borrow.do'
url_lend = r'http://172.16.22.104:8080/bsams/front/asset/asset_borrow_save.do'
url_return = r'http://172.16.22.104:8080/bsams/front/asset/asset_giveBack.do'
url_asset_return = r'http://172.16.22.104:8080/bsams/front/asset/asset_giveBack_save.do'
url_address = r'http://172.16.22.104:8080/bsams/front/asset_storage/asset_storage_list.do'
url_supplier = r'http://172.16.22.104:8080/bsams/front/asset_provider/asset_provider_list.do'
url_personal = r'http://172.16.22.104:8080/bsams/front/asset_user/user_info.do'
resp = requests.get(url)
print(resp.status_code)

# 验证码接口
resp1 = requests.get(url1)
print(resp1.status_code)

# 登录
data = {'taskId': 1,
        'loginName': 'test03',
        'password': '123456',
        'vericode': 'shtd'
        }
# 发送请求
se = requests.Session()
se.get(url)
se.get(url1)
resp2 = se.post(url, data=data)
print(resp2.status_code)

# 查询
url_info = r'http://172.16.22.108:8080/bsams/front/asset/asset_list.do'
resp = se.post(url2)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)
# 资产新增
# 构造 cookies
cookies = {'JSESSIONID': 'D27A081D1822F684C76A8EE42C3C892F'}
data = {
    'title': '戴尔灵越15',
    'storageId': 2,
    'providerId': 2
}
resp3 = requests.post(url_news_add, params=data, cookies=cookies)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 资产修改
asset_id = {'id': '1789'}
se.get(url_update, params=asset_id)
update_title = {
    'title': '戴尔灵越',
    'storageId': '维信科技发展有限公司',
    'providerId': '财务室'
}
resp = se.post(url_update, data=update_title)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 资产借用页面
asset_id = {'id': '134'}
resp = se.get(url_borrow, params=asset_id)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 资产借用
lend_id = {
    'id': '178',
    'departId': '软件部',
    'remark': '1',
}
resp = se.post(url_lend, data=lend_id)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 资产归还页面
asset_id = {'id': '155'}
resp = se.get(url_return, params=asset_id)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 资产归还
asset_id = {'id': '155'}
resp = se.post(url_asset_return, data=asset_id)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 查询存放地点
resp = se.post(url_address)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 查询存供应商
resp = se.post(url_supplier)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)

# 个人信息页面
resp = se.get(url_personal)
patt = r'<title>(.*?)</title>'
title = re.findall(patt, resp.text)
print(title)
